package com.caocaog.market.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caocaog.market.entity.OrderDelivery;
import com.caocaog.market.mapper.OrderDeliveryMapper;
import com.caocaog.market.service.IOrderDeliveryService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商品订配送信息表
 *
 * @author jeecg-boot
 * @date 2021-11-29
 */
@Service
@Transactional
@RequiredArgsConstructor
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OrderDelivery> implements IOrderDeliveryService {

    @Override
    public String addOrderDelivery(OrderDelivery orderDelivery) {
        // 去除前端返回的address字段中的"null"字符串
        if (StringUtils.isNotBlank(orderDelivery.getAddress()) && orderDelivery.getAddress().contains(StringPool.NULL)) {
            orderDelivery.setAddress(orderDelivery.getAddress().replace(StringPool.NULL, StringPool.EMPTY));
        }

        super.baseMapper.insert(orderDelivery);
        return orderDelivery.getId();
    }
}
